package com.hmyuan.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hmyuan.dao.SysDictionaryDataMapper;
import com.hmyuan.domain.SysDictionaryData;
import com.hmyuan.service.SysDictionaryDataService;
import com.hmyuan.util.DictionaryUtil;
import com.hmyuan.util.PageUtil;

@Service("sysDictionaryDataService")
public class SysDictionaryDataServiceImpl implements SysDictionaryDataService {
	@Resource
	SysDictionaryDataMapper sysDictionaryDataMapper;
	@Resource
	PageUtil pageUtil;
	
	@Override
	public PageInfo<SysDictionaryData> selectListByPage(
			SysDictionaryData sysDictionaryData, int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageNum, pageSize); // 核心分页代码
		List<SysDictionaryData> list = sysDictionaryDataMapper.selectList(sysDictionaryData);
		PageInfo<SysDictionaryData> pageInfo = new PageInfo<SysDictionaryData>(list);
		return pageInfo;
	}

	@Override
	public boolean insert(SysDictionaryData sysDictionaryData) {
		// TODO Auto-generated method stub
		int num = sysDictionaryDataMapper.insert(sysDictionaryData);
		
		DictionaryUtil.dictionary = new HashMap<String, Map<String,String>>();
		if("domainName".equals(sysDictionaryData.getName())||
				"fileConfig".equals(sysDictionaryData.getName())){
			pageUtil.fileDomainName();
		}
		return num==1?true:false;
	}

	@Override
	public List<SysDictionaryData> selectList(
			SysDictionaryData sysDictionaryData) {
		// TODO Auto-generated method stub
		return sysDictionaryDataMapper.selectList(sysDictionaryData);
	}

	@Override
	public SysDictionaryData selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return sysDictionaryDataMapper.selectByPrimaryKey(id);
	}

	@Override
	public boolean updateByPrimaryKeySelective(
			SysDictionaryData sysDictionaryData) {
		// TODO Auto-generated method stub
		int num = sysDictionaryDataMapper.updateByPrimaryKeySelective(sysDictionaryData);
		
		DictionaryUtil.dictionary = new HashMap<String, Map<String,String>>();
		if("domainName".equals(sysDictionaryData.getName())||
				"fileConfig".equals(sysDictionaryData.getName())){
			pageUtil.fileDomainName();
		}
		return num==1?true:false;
	}

	@Override
	public boolean deleteByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		int num = sysDictionaryDataMapper.deleteByPrimaryKey(id);
		
		DictionaryUtil.dictionary = new HashMap<String, Map<String,String>>();
		return num==1?true:false;	
	}
}
